package ttOrder.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ttOrder.model.Orders;

@Repository
public class OrdersDAOImpl extends BaseHibernateDAO<Orders> implements IOrdersDAO {
	@Autowired
	private SessionFactory sessionFactory;

	public Session getSession() {
		return this.sessionFactory.getCurrentSession();
	}

	@Override
	public List<Orders> findAllOrders() {
		Session session = getSession();
		String hql = " from Orders";
		@SuppressWarnings("unchecked")
		List<Orders> orders = session.createQuery(hql).list();
		return orders;
	}

	@Override
	public Orders getOrdersById(Integer id) {
		Session session = getSession();
		return (Orders) session.get(Orders.class, id);
	}

	@Override
	public void createOrders(Orders orders) throws Exception {
		Session session = getSession();
		session.save(orders);
	}

	@Override
	public String editOrders(Integer id) throws Exception {
		Session session = getSession();
		Orders orders = (Orders) session.get(Orders.class, id);
		orders.setOrderstatus(1);
		return null;

	}

	@Override
	public void editOrders1(Orders orders) throws Exception {
		Session session = getSession();
		session.update(orders);

	}

	@Override
	public void deleteOrders(Integer id) throws Exception {
		Orders orders = this.get(id);
		if (orders != null) {
			this.delete(orders);
		}
	}

}
